﻿using System;
using System.ComponentModel;

namespace HalconDotNet
{
	/// <summary>Represents an instance of a text segmentations result.</summary>
	// Token: 0x0200006C RID: 108
	public class HTextResult : HHandle
	{
		// Token: 0x06001904 RID: 6404 RVA: 0x0000883B File Offset: 0x00006A3B
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HTextResult() : base(HHandleBase.UNDEF)
		{
		}

		// Token: 0x06001905 RID: 6405 RVA: 0x0009F854 File Offset: 0x0009DA54
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HTextResult(IntPtr handle) : base(handle)
		{
			this.AssertSemType();
		}

		// Token: 0x06001906 RID: 6406 RVA: 0x0009F863 File Offset: 0x0009DA63
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HTextResult(HHandle handle) : base(handle)
		{
			this.AssertSemType();
		}

		// Token: 0x06001907 RID: 6407 RVA: 0x0009F872 File Offset: 0x0009DA72
		private void AssertSemType()
		{
			base.AssertSemType("text_result");
		}

		// Token: 0x06001908 RID: 6408 RVA: 0x0009F87F File Offset: 0x0009DA7F
		internal static int LoadNew(IntPtr proc, int parIndex, int err, out HTextResult obj)
		{
			obj = new HTextResult(HHandleBase.UNDEF);
			return obj.Load(proc, parIndex, err);
		}

		// Token: 0x06001909 RID: 6409 RVA: 0x0009F898 File Offset: 0x0009DA98
		internal static int LoadNew(IntPtr proc, int parIndex, int err, out HTextResult[] obj)
		{
			HTuple htuple;
			err = HTuple.LoadNew(proc, parIndex, err, out htuple);
			obj = new HTextResult[htuple.Length];
			for (int i = 0; i < htuple.Length; i++)
			{
				obj[i] = new HTextResult(HalconAPI.IsLegacyHandleMode() ? htuple[i].IP : htuple[i].H);
			}
			htuple.Dispose();
			return err;
		}

		/// <summary>
		///   Find text in an image.
		///   Modified instance represents: Result of the segmentation.
		/// </summary>
		/// <param name="image">Input image.</param>
		/// <param name="textModel">Text model specifying the text to be segmented.</param>
		// Token: 0x0600190A RID: 6410 RVA: 0x0009F908 File Offset: 0x0009DB08
		public HTextResult(HImage image, HTextModel textModel)
		{
			IntPtr proc = HalconAPI.PreCall(417);
			HalconAPI.Store(proc, 1, image);
			HalconAPI.Store(proc, 0, textModel);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			GC.KeepAlive(image);
			GC.KeepAlive(textModel);
		}

		/// <summary>Clear a text result.</summary>
		/// <param name="textResultID">Text result to be cleared.</param>
		// Token: 0x0600190B RID: 6411 RVA: 0x0009F968 File Offset: 0x0009DB68
		public static void ClearTextResult(HTextResult[] textResultID)
		{
			HTuple htuple = HHandleBase.ConcatArray(textResultID);
			IntPtr proc = HalconAPI.PreCall(414);
			HalconAPI.Store(proc, 0, htuple);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(htuple);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(textResultID);
		}

		/// <summary>
		///   Clear a text result.
		///   Instance represents: Text result to be cleared.
		/// </summary>
		// Token: 0x0600190C RID: 6412 RVA: 0x0009F9AC File Offset: 0x0009DBAC
		public void ClearTextResult()
		{
			IntPtr proc = HalconAPI.PreCall(414);
			base.Store(proc, 0);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Query an iconic value of a text segmentation result.
		///   Instance represents: Text result.
		/// </summary>
		/// <param name="resultName">Name of the result to be returned. Default: "all_lines"</param>
		/// <returns>Returned result.</returns>
		// Token: 0x0600190D RID: 6413 RVA: 0x0009F9E0 File Offset: 0x0009DBE0
		public HObject GetTextObject(HTuple resultName)
		{
			IntPtr proc = HalconAPI.PreCall(415);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, resultName);
			HalconAPI.InitOCT(proc, 1);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(resultName);
			HObject result;
			num = HObject.LoadNew(proc, 1, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Query an iconic value of a text segmentation result.
		///   Instance represents: Text result.
		/// </summary>
		/// <param name="resultName">Name of the result to be returned. Default: "all_lines"</param>
		/// <returns>Returned result.</returns>
		// Token: 0x0600190E RID: 6414 RVA: 0x0009FA38 File Offset: 0x0009DC38
		public HObject GetTextObject(string resultName)
		{
			IntPtr proc = HalconAPI.PreCall(415);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, resultName);
			HalconAPI.InitOCT(proc, 1);
			int num = HalconAPI.CallProcedure(proc);
			HObject result;
			num = HObject.LoadNew(proc, 1, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Query a control value of a text segmentation result.
		///   Instance represents: Text result.
		/// </summary>
		/// <param name="resultName">Name of the result to be returned. Default: "class"</param>
		/// <returns>Value of ResultName.</returns>
		// Token: 0x0600190F RID: 6415 RVA: 0x0009FA88 File Offset: 0x0009DC88
		public HTuple GetTextResult(HTuple resultName)
		{
			IntPtr proc = HalconAPI.PreCall(416);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, resultName);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(resultName);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Query a control value of a text segmentation result.
		///   Instance represents: Text result.
		/// </summary>
		/// <param name="resultName">Name of the result to be returned. Default: "class"</param>
		/// <returns>Value of ResultName.</returns>
		// Token: 0x06001910 RID: 6416 RVA: 0x0009FAE0 File Offset: 0x0009DCE0
		public HTuple GetTextResult(string resultName)
		{
			IntPtr proc = HalconAPI.PreCall(416);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, resultName);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Find text in an image.
		///   Modified instance represents: Result of the segmentation.
		/// </summary>
		/// <param name="image">Input image.</param>
		/// <param name="textModel">Text model specifying the text to be segmented.</param>
		// Token: 0x06001911 RID: 6417 RVA: 0x0009FB30 File Offset: 0x0009DD30
		public void FindText(HImage image, HTextModel textModel)
		{
			this.Dispose();
			IntPtr proc = HalconAPI.PreCall(417);
			HalconAPI.Store(proc, 1, image);
			HalconAPI.Store(proc, 0, textModel);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			GC.KeepAlive(image);
			GC.KeepAlive(textModel);
		}
	}
}
